#!/bin/bash
cat <<EOF
                                    .                          ooooooooo
                                  .o8                         d"""""""8'
 .ooooo.   .ooooo.  ooo. .oo.   .o888oo  .ooooo.   .oooo.o          .8'
d88' \`"Y8 d88' \`88b \`888P"Y88b    888   d88' \`88b d88(  "8         .8'
888       888ooo888  888   888    888   888   888 \`"Y88b.         .8'
888   .o8 888    .o  888   888    888 . 888   888 o.  )88b       .8'
\`Y8bod8P' \`Y8bod8P' o888o o888o   "888" \`Y8bod8P' 8""888P'      .8'

EOF

cat <<EOF
################################################################################
#                                   ALERT!                                     #
# You're entering into a secured area! Your IP, Login Time, Username has been  #
# noted and has been sent to the server administrator!                         #
# This service is restricted to authorized users only. All activities on this  #
# system are logged. Unauthorized access will be fully investigated and        #
# reported to the appropriate law enforcement agencies.                        #
################################################################################

EOF

echo -e "主机名称 = `hostname`"
echo -e "操作系统 = `cat /etc/centos-release`"
echo -e "内核版本 = `uname -r`"
echo -e "硬件架构 = `uname -m`"

GROUP="未知"
ROLE="未知"
LOCATION="未知"
if [[ `hostname` =~ ^TN([[:alpha:]]+)DB([[:digit:]]{2})_([M|S])(SK|XL|GL|BA)([[:digit:]])$ ]];
then
	case ${BASH_REMATCH[1]} in
		Loan)    GROUP="资产端"         ;;
		Invest)  GROUP="理财端"         ;;
		Biz)     GROUP="商业智能"       ;;
		Hadoop)  GROUP="大数据"         ;;
		Fundmtl) GROUP="基础架构"       ;;
		Rskmgmt) GROUP="风险控制"       ;;
		Bench)   GROUP="脱敏、基准测试" ;;
		*) ;;
	esac
	case ${BASH_REMATCH[3]} in
		M) ROLE="主库" ;;
		S) ROLE="从库" ;;
		*) ;;
	esac
	case ${BASH_REMATCH[4]} in
		XL) LOCATION="西丽"            ;;
		SK) LOCATION="蛇口"            ;;
		GL) LOCATION="阿里云 - 观澜"   ;;
		BA) LOCATION="阿里云 - 保税区" ;;
		*) ;;
	esac
fi
echo -e "资产分组 = ${GROUP}"
echo -e "角色担当 = ${ROLE}"
echo -e "数据中心 = ${LOCATION}"

NETWORK='' 
if grep -q 'release 6' /etc/centos-release
then
	NETWORK=`ifconfig -a | awk 'BEGIN {FS="\n"; RS=""} {print $1,$2}' | grep -v 'lo' | awk '{print "           "$1,$7}'`
else
	NETWORK=`ifconfig -a | awk 'BEGIN {FS="\n"; RS=""} {print $1,$2}' | grep -v 'lo' | awk '{print "           "$1,$6}'`
fi
 
echo -e "网络地址 = \n${NETWORK}"
UPTIME="$(uptime)"
U1=$(echo ${UPTIME} | awk -F'( |,|:)+' '{print $1 ":" $2 ":" $3}')
U2=$(echo ${UPTIME} | awk -F'( |,|:)+' '{if ($6=="min") m=$5; else {if ($6~/^day/) {d=$5;h=$7;m=$8} else {h=$5;m=$6}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}')
U3=$(echo ${UPTIME} | grep -ohe '[0-9.*] user[s,]'| sed 's/,//g')
U4=$(echo ${UPTIME} | grep -ohe 'load average[s:][: ].*' | sed 's/,//g' | awk '{ print $3" - "$4" - "$5 }')
MEMORY=$(free -mt | grep Mem: | awk '{ print "Total " $2 " MB - Used " $3 " MB - Free " $4 " MB - Cache " $6 " MB - Available " $7 " MB"}')
echo -e "当前时间 = ${U1}"
echo -e "运行时间 = ${U2}"
echo -e "在线用户 = ${U3}"
echo -e "系统负载 = ${U4}"
echo -e "内存使用 = ${MEMORY}"
echo -e "当前用户 = `whoami`"
 
echo -e "--------------------------------------------------------------------------------"
